﻿using System;
using System.Globalization;

namespace Microsoft.Office.OneNote
{
    [OneNoteXmlElement("Dimensions")]
    public sealed class OneNotePageDimensions : OneNoteObject, IEquatable<OneNotePageDimensions>
    {
        private const string ToStringFormat = "Width={0}, Height={1}";

        internal static readonly OneNoteProperty WidthProperty = OneNoteProperty.Register(
            "width", typeof(Double), typeof(OneNotePageDimensions));
        
        internal static readonly OneNoteProperty HeightProperty = OneNoteProperty.Register(
            "height", typeof(Double), typeof(OneNotePageDimensions));

        internal OneNotePageDimensions()
        {
        }

        public OneNotePageDimensions(double width, double height)
        {
            SetValue(WidthProperty, width);
            SetValue(HeightProperty, height);
        }

        public double Width
        {
            get { return GetValue<Double>(WidthProperty); }
        }

        public double Height
        {
            get { return GetValue<Double>(HeightProperty); }
        }

        public override int GetHashCode()
        {
            return Width.GetHashCode() ^ Height.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return this.EqualsHelper(obj);
        }

        public bool Equals(OneNotePageDimensions other)
        {
            if (ReferenceEquals(other, null))
            {
                return false;
            }

            return DoubleHelper.AreClose(Width, other.Width) &&
                   DoubleHelper.AreClose(Height, other.Height);
        }

        public override string ToString()
        {
            return String.Format(CultureInfo.InvariantCulture, ToStringFormat, Width, Height);
        }
    }
}
